@echo off

chcp 65001
REM by jackie lee @ 2021.10.11
REM such as: lib-src-copy.bat D:\Document\temp\stm32\en.stm32cubef1_v1.8.0 D:\Document\LeeSp\Stm32Pro\Template\HalTemplate
REM 源包类似：en.stm32cubef1_v1.8.0  chcp修改编码为utf-8
REM 源包目录 %1 目标项目路径 %2

SET "LIB_DIR=%~1"
SET "TARGET_DIR=%~2"

REM 判断是否参数合法
if not defined LIB_DIR goto nosource
if not exist %LIB_DIR% goto nosource
if not defined TARGET_DIR goto noproject
if not exist %TARGET_DIR% goto noproject

REM SET LIB_DIR=D:\Document\temp\stm32\en.stm32cubef1_v1.8.0
REM SET TARGET=D:\Document\LeeSp\Stm32Pro\Template\HalTemplate\CMSIS
SET TARGET=%TARGET_DIR%\Libraries\CMSIS
SET TARGET_DRIVER=%TARGET_DIR%\Libraries\STM32
SET TARGET_USER=%TARGET_DIR%\User

if not exist %LIB_DIR% goto failure

REM check target
if not exist %TARGET% mkdir %TARGET%
if not exist %TARGET_DRIVER% mkdir %TARGET_DRIVER%
if not exist %TARGET_DRIVER%\Inc mkdir %TARGET_DRIVER%\Inc
if not exist %TARGET_DRIVER%\Src mkdir %TARGET_DRIVER%\Src
if not exist %TARGET_USER% mkdir %TARGET_USER%

COPY /Y %LIB_DIR%\Drivers\CMSIS\Core\Include\cmsis_armcc.h %TARGET%
COPY /Y %LIB_DIR%\Drivers\CMSIS\Core\Include\cmsis_armclang.h %TARGET%
COPY /Y %LIB_DIR%\Drivers\CMSIS\Core\Include\cmsis_compiler.h %TARGET%
COPY /Y %LIB_DIR%\Drivers\CMSIS\Core\Include\core_cm3.h %TARGET%
COPY /Y %LIB_DIR%\Drivers\CMSIS\Device\ST\STM32F1xx\Source\Templates\arm\startup_stm32f103xe.s %TARGET%


REM config
COPY /Y %LIB_DIR%\Projects\STM3210E_EVAL\Templates\Inc\main.h %TARGET_USER%
COPY /Y %LIB_DIR%\Projects\STM3210E_EVAL\Templates\Src\main.c %TARGET_USER%
COPY /Y %LIB_DIR%\Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f1xx.h %TARGET_USER%
COPY /Y %LIB_DIR%\Projects\STM3210E_EVAL\Templates\Inc\stm32f1xx_hal_conf.h %TARGET_USER%
COPY /Y %LIB_DIR%\Projects\STM3210E_EVAL\Templates\Src\stm32f1xx_hal_msp.c %TARGET_USER%
COPY /Y %LIB_DIR%\Projects\STM3210E_EVAL\Templates\Inc\stm32f1xx_it.h %TARGET_USER%
COPY /Y %LIB_DIR%\Projects\STM3210E_EVAL\Templates\Src\stm32f1xx_it.c %TARGET_USER%
COPY /Y %LIB_DIR%\Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f103xe.h %TARGET_USER%
COPY /Y %LIB_DIR%\Drivers\CMSIS\Device\ST\STM32F1xx\Include\system_stm32f1xx.h %TARGET_USER%
REM TYPE null > %TARGET_USER%\system_stm32f1xx.h
COPY /Y %LIB_DIR%\Projects\STM3210E_EVAL\Templates\Src\system_stm32f1xx.c %TARGET_USER%

REM driver files
XCOPY /Y /S %LIB_DIR%\Drivers\STM32F1xx_HAL_Driver\Inc %TARGET_DRIVER%\Inc
XCOPY /Y /S %LIB_DIR%\Drivers\STM32F1xx_HAL_Driver\Src %TARGET_DRIVER%\Src

goto end

:nosource
echo input the stm32cubef1_v1.xx folder for param 1
goto end

:noproject
echo input the smt32 project folder for param 2
goto end

:failure
echo %LIB_DIR% not exists


:end

exit

